package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoUserFollowers;
import com.muyu.danmo.service.IDanmoUserFollowersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 粉丝Controller
 *
 * @author yangle
 * @date 2024-11-15
 */
@RestController
@RequestMapping("/userFollowers")
public class DanmoUserFollowersController extends BaseController {
    @Autowired
    private IDanmoUserFollowersService danmoUserFollowersService;

    /**
     * 查询粉丝列表
     */
//    @RequiresPermissions("system:userFollowers:list")
    @GetMapping("/list")
    public Result<TableDataInfo<DanmoUserFollowers>> list(DanmoUserFollowers danmoUserFollowers) {
        startPage();
        List<DanmoUserFollowers> list = danmoUserFollowersService.selectDanmoUserFollowersList(danmoUserFollowers);
        return getDataTable(list);
    }

    /**
     * 导出粉丝列表
     */
//    @RequiresPermissions("system:userFollowers:export")
    @Log(title = "粉丝", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoUserFollowers danmoUserFollowers) {
        List<DanmoUserFollowers> list = danmoUserFollowersService.selectDanmoUserFollowersList(danmoUserFollowers);
        ExcelUtil<DanmoUserFollowers> util = new ExcelUtil<DanmoUserFollowers>(DanmoUserFollowers.class);
        util.exportExcel(response, list, "粉丝数据");
    }

    /**
     * 获取粉丝详细信息
     */
//    @RequiresPermissions("system:userFollowers:query")
    @GetMapping(value = "/{followerId}")
    public Result getInfo(@PathVariable("followerId") Long followerId) {
        return Result.success(danmoUserFollowersService.selectDanmoUserFollowersByFollowerId(followerId));
    }

    /**
     * 新增粉丝
     */
//    @RequiresPermissions("system:userFollowers:add")
    @Log(title = "粉丝", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoUserFollowers danmoUserFollowers) {
        danmoUserFollowersService.insertDanmoUserFollowers(danmoUserFollowers);
        return Result.success(danmoUserFollowers, "新增成功");
    }

    /**
     * 修改粉丝
     */
//    @RequiresPermissions("system:userFollowers:edit")
    @Log(title = "粉丝", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoUserFollowers danmoUserFollowers) {
        return danmoUserFollowersService.updateDanmoUserFollowers(danmoUserFollowers);
    }

    /**
     * 删除粉丝
     */
//    @RequiresPermissions("system:userFollowers:remove")
    @Log(title = "粉丝", businessType = BusinessType.DELETE)
    @DeleteMapping("/{followerIds}")
    public Result remove(@PathVariable Long[] followerIds) {
        return danmoUserFollowersService.deleteDanmoUserFollowersByFollowerIds(followerIds);
    }

    /**
     * 查询粉丝数量
     */
/*    @GetMapping("/count/{followeeId}")
    public Result count(@RequestParam Long followeeId)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser==null){
            return Result.notLoggedIn("请登录");
        }
        return Result.success(danmoUserFollowersService.selectDanmoUserFollowersList(null).size());
    }*/
    @GetMapping("/count")
    public Result count() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null) {
            return Result.notLoggedIn("请登录");
        }
        return Result.success(danmoUserFollowersService.selectDanmoUserFollowersList(null).size());
    }

    /**
     * 查询粉丝列表
     */
    @GetMapping("/list/{followeeId}")
    public Result list(@PathVariable Long followeeId) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null) {
            return Result.notLoggedIn("请登录");
        }
        return Result.success(danmoUserFollowersService.selectDanmoUserFollowersList(null));
    }

}
